package com.xcity.game.item.effect;

import com.xcity.db.entity.Player;
import com.xcity.game.common.Cause;
import com.xcity.game.item.DropGroupTemplate;
import com.xcity.game.item.GameItem;
import com.xcity.game.item.ItemEffect;
import com.xcity.game.item.ItemException;
import com.xcity.game.item.drop.Drop;
import com.xcity.game.item.drop.listener.DropListener;
import com.xcity.game.item.listener.BagListener;

import naga.x.App;
import naga.x.game.template.TemplateService;

/**
 * 掉落物品效果
 * @author yang.li
 *
 */
public class GetDropGroupItemEffect implements ItemEffect {

	@Override
	public boolean effect(Player player, GameItem item, int count, BagListener listener) throws ItemException {
		int dropGoupId = item.getTemplate().getParameter(0);
		DropGroupTemplate dropGroup = App.getApp().getServiceManager().get(TemplateService.class).get(DropGroupTemplate.class, dropGoupId);
		Drop drop = dropGroup.getDrop();
		DropListener dlsr = null;
		if (listener != null && listener instanceof DropListener) {
			dlsr = (DropListener) listener;
		}
		while (count-- > 0) {
			drop.drop(Drop.RND, player, Cause.DROP_GROUP, dlsr);
		}
		return true;
	}

}
